package cn.jbolt.common.interceptor;


import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;

import cn.jbolt.common.exception.AppException;


public class AppExceptionInterceptor implements Interceptor {

	@Override
	public void intercept(Invocation inv) {
		Controller controller = inv.getController();
		Ret result = new Ret();
		result.set("_success", false);
		try {
			inv.invoke();
		} catch (AppException e) {
			result.set("_message", e.getMessage());
			controller.renderJson(result);
		}catch(Exception e){
			e.printStackTrace();
			result.set("_message","500 Internal Error!");
			controller.renderJson(result);
		}
	}

}
